package org.zcl.service.third;

import com.google.common.base.Throwables;
import lombok.extern.slf4j.Slf4j;
import org.zcl.entity.response.ChannelResponse;
import org.zcl.service.PayService;

/**
 * <p>
 * </p>
 *
 * @author Chenglin Zhu
 * @since 2022-08-09 11:16:53
 */
@Slf4j
public abstract class AbstractThirdPayService<T> implements PayService<T> {

    @Override
    public ChannelResponse applyPay(T t) {
        ChannelResponse channelResponse = new ChannelResponse();
        try {
            log.info("调用三方渠道支付请求参数:{}",t);
            channelResponse = doApplyPay(t);
        } catch (Exception e) {
            log.error("调用三方渠道支付出现异常:{}", Throwables.getStackTraceAsString(e));
        }
        log.info("调用三方渠道支付返回上游结果:{}", channelResponse);
        return channelResponse;
    }


    protected abstract ChannelResponse doApplyPay(T t) throws Exception;

}
